/**
 * Created by aliceyxie on 2015/7/21.
 */
$(function() {

    $.fn.bannerShow = function(g) {
        g = jQuery.extend({wraper: "fshow",autotime: 6000,isAuto: true,ind: 0,changeColor: null}, g || {});
        return this.each(function() {
            var o;
            var n = 0;
            var i = this;
            var j = $("#bnav"), k = $("li", j);
            var h = [["#002c4a", "#005584"], ["#35ac03", "#3f4303"],["#ca4a5e", "#e06a77"] , ["18bbff", "#00486b"]];
            $(this).hover(function() {
                g.isAuto = false
            }, function() {
                g.isAuto = true
            });
            m(0);
            k.each(function(p, q) {
                $(q).mouseover(function() {
                    n = p;
                    k.removeClass().eq(n).addClass("current");
                    m(n)
                })
            });
            o = setInterval(function() {
                if (!g.isAuto) {
                    return false
                }
                k.each(function(p, q) {
                    if ($(q).hasClass("current")) {
                        n = p
                    }
                    m(n)
                });
                if (n == k.size() - 1) {
                    n = 0;
                    m(n);
                    k.removeClass().eq(n).addClass("current")
                } else {
                    n += 1;
                    m(n);
                    k.removeClass().eq(n).addClass("current")
                }
            }, g.autotime);
            function m(p) {
                $(".banners", i).hide();
                $(".banners", i).eq(p).show();
                if (g.changeColor) {
                    g.changeColor(h[p]).set()
                }
            }
        })
    };
    if (!window.ActiveXObject && !!document.createElement("canvas").getContext) {
        $.getScript("https://sqimg.qq.com/qq_product_operations/im/https_src/js/cav.js", function() {
            var t = {width: 1.5,height: 1.5,depth: 10,segments: 12,slices: 6,xRange: 0.8,yRange: 0.1,zRange: 1,ambient: "#525252",diffuse: "#FFFFFF",speed: 0.0002};
            var G = {count: 2,xyScalar: 1,zOffset: 100,ambient: "#002c4a",diffuse: "#005584",speed: 0.001,gravity: 1200,dampening: 0.95,minLimit: 10,maxLimit: null,minDistance: 20,maxDistance: 400,autopilot: false,draw: false,bounds: CAV.Vector3.create(),step: CAV.Vector3.create(Math.randomInRange(0.2, 1), Math.randomInRange(0.2, 1), Math.randomInRange(0.2, 1))};
            var m = "canvas";
            var E = "svg";
            var x = {renderer: m};
            var i, n = Date.now();
            var L = CAV.Vector3.create();
            var k = CAV.Vector3.create();
            var z = document.getElementById("container");
            var w = document.getElementById("anitOut");
            var D, I, h, q, y;
            var g;
            var r;
            function C() {
                F();
                p();
                s();
                B();
                v();
                K(z.offsetWidth, z.offsetHeight);
                o()
            }
            function F() {
                g = new CAV.CanvasRenderer();
                H(x.renderer)
            }
            function H(N) {
                if (D) {
                    w.removeChild(D.element)
                }
                switch (N) {
                    case m:
                        D = g;
                        break
                }
                D.setSize(z.offsetWidth, z.offsetHeight);
                w.appendChild(D.element)
            }
            function p() {
                I = new CAV.Scene()
            }
            function s() {
                I.remove(h);
                D.clear();
                q = new CAV.Plane(t.width * D.width, t.height * D.height, t.segments, t.slices);
                y = new CAV.Material(t.ambient, t.diffuse);
                h = new CAV.Mesh(q, y);
                I.add(h);
                var N, O;
                for (N = q.vertices.length - 1; N >= 0; N--) {
                    O = q.vertices[N];
                    O.anchor = CAV.Vector3.clone(O.position);
                    O.step = CAV.Vector3.create(Math.randomInRange(0.2, 1), Math.randomInRange(0.2, 1), Math.randomInRange(0.2, 1));
                    O.time = Math.randomInRange(0, Math.PIM2)
                }
            }
            function B() {
                var O, N;
                for (O = I.lights.length - 1; O >= 0; O--) {
                    N = I.lights[O];
                    I.remove(N)
                }
                D.clear();
                for (O = 0; O < G.count; O++) {
                    N = new CAV.Light(G.ambient, G.diffuse);
                    N.ambientHex = N.ambient.format();
                    N.diffuseHex = N.diffuse.format();
                    I.add(N);
                    N.mass = Math.randomInRange(0.5, 1);
                    N.velocity = CAV.Vector3.create();
                    N.acceleration = CAV.Vector3.create();
                    N.force = CAV.Vector3.create()
                }
            }
            function K(O, N) {
                D.setSize(O, N);
                CAV.Vector3.set(L, D.halfWidth, D.halfHeight);
                s()
            }
            function o() {
                i = Date.now() - n;
                u();
                M();
                requestAnimationFrame(o)
            }
            function u() {
                var Q, P, O, R, T, V, U, S = t.depth / 2;
                CAV.Vector3.copy(G.bounds, L);
                CAV.Vector3.multiplyScalar(G.bounds, G.xyScalar);
                CAV.Vector3.setZ(k, G.zOffset);
                for (R = I.lights.length - 1; R >= 0; R--) {
                    T = I.lights[R];
                    CAV.Vector3.setZ(T.position, G.zOffset);
                    var N = Math.clamp(CAV.Vector3.distanceSquared(T.position, k), G.minDistance, G.maxDistance);
                    var W = G.gravity * T.mass / N;
                    CAV.Vector3.subtractVectors(T.force, k, T.position);
                    CAV.Vector3.normalise(T.force);
                    CAV.Vector3.multiplyScalar(T.force, W);
                    CAV.Vector3.set(T.acceleration);
                    CAV.Vector3.add(T.acceleration, T.force);
                    CAV.Vector3.add(T.velocity, T.acceleration);
                    CAV.Vector3.multiplyScalar(T.velocity, G.dampening);
                    CAV.Vector3.limit(T.velocity, G.minLimit, G.maxLimit);
                    CAV.Vector3.add(T.position, T.velocity)
                }
                for (V = q.vertices.length - 1; V >= 0; V--) {
                    U = q.vertices[V];
                    Q = Math.sin(U.time + U.step[0] * i * t.speed);
                    P = Math.cos(U.time + U.step[1] * i * t.speed);
                    O = Math.sin(U.time + U.step[2] * i * t.speed);
                    CAV.Vector3.set(U.position, t.xRange * q.segmentWidth * Q, t.yRange * q.sliceHeight * P, t.zRange * S * O - S);
                    CAV.Vector3.add(U.position, U.anchor)
                }
                q.dirty = true
            }
            function M() {
                D.render(I)
            }
            function J(O) {
                var Q, N, S = O;
                var P = function(T) {
                    for (Q = 0, l = I.lights.length; Q < l; Q++) {
                        N = I.lights[Q];
                        N.ambient.set(T);
                        N.ambientHex = N.ambient.format()
                    }
                };
                var R = function(T) {
                    for (Q = 0, l = I.lights.length; Q < l; Q++) {
                        N = I.lights[Q];
                        N.diffuse.set(T);
                        N.diffuseHex = N.diffuse.format()
                    }
                };
                return {set: function() {
                    P(S[0]);
                    R(S[1])
                }}
            }
            function v() {
                window.addEventListener("resize", j)
            }
            function A(N) {
                CAV.Vector3.set(k, N.x, D.height - N.y);
                CAV.Vector3.subtract(k, L)
            }
            function j(N) {
                K(z.offsetWidth, z.offsetHeight);
                M()
            }
            C();
            $("#fshow").bannerShow({changeColor: J})
        })
    } else {
        $("#fshow").bannerShow()
    }
    $("#copytime").html((new Date()).getFullYear());
    $("#ovpage").click(function(g) {
        g.preventDefault();
        $("html, body").animate({scrollTop: $("#container").height()}, 1000)
    });
    var c = function() {
    };

    // if (typeof (pgvMain) != "function") {
    //     // var f = "https://pingjs.qq.com/tcss.ping.https.js?v=1";
    //     var f = "http://bm.com.cn/";
    //     $.getScript(f, function() {
    //         if (typeof (pgvMain) == "function") {
    //             pgvMain()
    //         }
    //         c = pgvSendClick;
    //         $(".forTcss").click(function() {
    //             var g = $(this).attr("name");
    //             var h = window.setTimeout(function() {
    //                 c({hottag: g})
    //             }, 500)
    //         })
    //     })
    // }
    window.online_resp = function(g) {
        if (g && g.c) {
            $("#cur_online").text(g.c.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
            $("#max_online").text(g.h.toString().replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,"));
        }
    };
    $.getJSON("https://mma.qq.com/cgi-bin/im/online&callback=?", function(g) {
    });
    var swf=/^https/.test(window.location)?"https://im.qq.com/online/flash/20160926.swf":"http://im.qq.com/online/flash/flash20140304.swf";
    swfobject.embedSWF(swf, "flashBox", "910", "700", "9.0.0", "expressInstall.swf");
    $("#viewOnline").click(function(g) {
        g.preventDefault();
        $("#flashDiv").show();
        $("#overlay").show();
        $("#overlay").css({height: $(document).height()});
        c({hottag: "pcqq.openflash"})
    });
    $("#flashClose").click(function(g) {
        g.preventDefault();
        $("#flashDiv").hide();
        $("#overlay").hide()
    });
    var d = $(".ipage");
    var e = [], b = [];
    var a = $(window).height();
    $(d).each(function(g, h) {
        e[g] = $(h).offset().top + Math.floor($(h).height() / 2);
        b[g] = $(h).find(".imgwrap");
    });
    $(window).resize(function() {
        a = $(window).height()
    });
    var perCount=5; ///每次加载5屏
    var currentPage=5;
    var repbglen=$(".pagetemp").length;
    var loadpage=function(start,end){

        var pagehtml="";
        for(i=start;i<end && i<repbglen;i++)
        {
            pagehtml+=$("#page"+(repbglen-i)).html();
        }
        $("#pgmain").append(pagehtml);
        currentPage+=perCount;
        if(currentPage>=repbglen)
        {
            $(".seemore").css("display","none");
        }
        d = $(".ipage");
        $(d).each(function(g, h) {
            e[g] = $(h).offset().top + Math.floor($(h).height() / 2);
            b[g] = $(h).find(".imgwrap");
        });
    };
    $(".seemore").click(function(){
        $(".seemore p").text("正在加载...");
        loadpage(currentPage,currentPage+perCount);
        $(".seemore p").text("查看更多");
    });
    var ticcount=0;
    $("#toTop").click(function(g){
        g.preventDefault();
        $("html, body").animate({scrollTop: 0}, 0);
    });
    $("#toTop").mouseover(function(g){
        g.preventDefault();
        ticcount=0;
        $("#toTop a").css("background-position","0 -71px");
    });
    $("#toTop").mouseout(function(g){
        g.preventDefault();
        $("#toTop a").css("background-position","0 0px");
    });
    $("#toTop").mousedown(function(g){
        g.preventDefault();
        $("#toTop a").css("background-position","0 -150px");
    });
    function pmove(){
        var left=parseInt($(".fig_26_2").css("left").replace('px',''));
        var top=parseInt($(".fig_26_2").css("top").replace('px',''));
        setTimeout(function(){
            left-=2;
            top-=2;
            $(".fig_26_2").css({"left":left+"px","top":top+"px"});
            if(left>570 && top>451){
                setTimeout(arguments.callee,120);
            }
        },120);
        setTimeout(function(){
            $(".fig_26_1").css("background-position","0 -20px");
            $(".fig_cir26").css("background-position","-269px 0px");
        },2000);

        setTimeout(function(){
            $(".fig_26_2").removeClass("showbg");
            $(".fig_cir26").css("background-position","-538px 0px");
        },4000);
    }
    $(window).scroll(function() {
        var g = $(window).scrollTop();
        //控制置顶按钮的显示,初始状态显示5屏，且不显示置顶按钮
        if(g>$("#container").height()+720*5-180)
        {
            $("#toTop").css("display","block");
        }
        else
        {
            $("#toTop").css("display","none");
        }
        $(e).each(function(h, j) {

            if (Math.floor(a / 2) + g >= j) {
                if (!$(b[h]).hasClass("showbg") && $(b[h]).hasClass("fig_24")) {
                    $(b[h]).addClass("showbg");
                    setTimeout(function(){$(".fig_24_text").css("background-image","url(https://sqimg.qq.com/qq_product_operations/im/pcqq/7/rect.png)");},1500);
                    setTimeout(function(){$("#sp3").css("display","inline-block");},2500);

                    var strarray=["Q","Q","的","围巾","再","细","一","点"];
                    /*考虑闭包问题*/
                    for (var j = 0; j < strarray.length; j++) {
                        setTimeout((function(j){
                            return function(){
                                $('#sp2').append(strarray[j]);
                            }
                        })(j), (j+1)*300+2500);
                    };
                }
                else if(!$(b[h]).hasClass("showbg") && $(b[h]).hasClass("fig_26"))
                {
                    $(".fig_26").addClass("showbg");
                    $(".fig_26_1").addClass("showbg");
                    $(".fig_cir26").addClass("showbg");
                    $(".fig_26_2").addClass("showbg");
                    pmove();
                }
                else if(!$(b[h]).hasClass("showbg"))
                {
                    $(b[h]).addClass("showbg");
                }
            }
        });
    });
});